package fy.form.listen;

//import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.seeyon.apps.collaboration.event.*;
//import com.seeyon.apps.collaboration.manager.ColManager;
//import com.seeyon.apps.form.bo.FormBO;
//import com.seeyon.apps.form.bo.FormElementBO;
//import com.seeyon.apps.form.manager.FormManager;
//import com.seeyon.apps.form.po.GovForm;
import com.seeyon.ctp.util.annotation.ListenEvent;

import fy.form.listen.manager.CommonFormHandlerManager;
import fy.form.listen.set.IFormSetting;
import fy.util.MyUtil;

public class FyFormLinstener {

    private static final Log logger = LogFactory.getLog(FyFormLinstener.class);

//	private void printLog(Exception msg) {
//		logger.error(msg);
//		System.err.println(msg);
//	}
    private void printLog(String msg) {
        logger.info(msg);
//        System.out.println(msg);
    }

    /**
     * 流程提交通过事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationProcessEvent.class, async = true)
    public void onPress(CollaborationProcessEvent event) {
        printLog("press");
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.PROCESS_STATUS);
    }

    /**
     * 流程结束事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationFinishEvent.class, async = true)
    public void onFinish(CollaborationFinishEvent event) {
        printLog("finish");
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.FINISH_STATUS);
    }

    /**
     * 发送表单事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationStartEvent.class, async = true)
    public void onFlowStart(CollaborationStartEvent event) {
    	try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.START_STATUS);
    }

    /**
     * 终止表单事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationStopEvent.class, async = true)
    public void onFlowStop(CollaborationStopEvent event) {
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.STOP_STATUS);
    }

    /**
     * 撤销表单事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationCancelEvent.class, async = true)
    public void onFlowCancel(CollaborationCancelEvent event) {
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.CANCEL_STATUS);
    }

    /**
     * 表单回退事件
     *
     * @param event
     */
    @ListenEvent(event = CollaborationStepBackEvent.class, async = true)
    public void onFlowStepBack(CollaborationStepBackEvent event) {
        CommonFormHandlerManager.operate(event.getSummaryId(),
                MyUtil.getRealPath(FyFormLinstener.class),
                IFormSetting.STEPBACK_STATUS);
    }

}
